import { getUserSelect } from '@/api/order'
import { ref } from 'vue'

/**
 * 分页获取公司下拉数据，带出所有联系人及对应的账号
 */
export const useGetCustomerOptions = () => {
  // 获取下拉选项加载
  const loading = ref(false)

  // 获取下拉选项请求参数
  const getOptionsParam = ref({
    limit: 50,
    page: 1,
    name: '',
  })

  // 公司下拉选项
  const options = ref<Array<CustomerOption>>([])

  /**
   * 获取下拉选项
   */
  const getOptions = async () => {
    try {
      loading.value = true
      const res = await getUserSelect(getOptionsParam.value)
      loading.value = false
      options.value = res.data.data.rows
    } catch (error) {
      loading.value = false
    }
  }

  return {
    options,
    loading,
    getOptionsParam,
    getOptions,
  }
}
